package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hea7en
 * @Date: 2024/6/17 4:55 PM
 * @Description: 管理端订单管理
 */
@Slf4j
@RequestMapping("/admin/order")
@RestController("adminOrderController")
@Api(tags = "管理端订单管理接口")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 订单信息分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单信息分页查询")
    public Result<PageResult> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult page = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 获取订单统计信息
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("获取订单统计信息")
    public OrderStatisticsVO getOrderStatistics() {
        return orderService.getOrderStatistics();
    }

    /**
     * 获取订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("获取订单详情")
    public Result<OrderVO> getDetails(@PathVariable Long id) {
        OrderVO orderVO = orderService.getDetails(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result orderConfirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.orderConfirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("拒单")
    public Result orderRejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        orderService.orderRejection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result orderCancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.orderCancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result orderDelivery(@PathVariable Long id) {
        orderService.orderDelivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result orderComplete(@PathVariable("id") Long id) {
        orderService.orderComplete(id);
        return Result.success();
    }
}
